<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>AI交友 - 智能筛选</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    
    <style>
        :root {
            --primary: #6366f1;
            --primary-light: #8b5cf6;
            --primary-dark: #4f46e5;
            --secondary: #10b981;
            --text-primary: #1f2937;
            --text-secondary: #6b7280;
            --text-light: #9ca3af;
            --bg-light: #f9fafb;
            --bg-white: #ffffff;
            --border-light: #e5e7eb;
            --radius: 12px;
            --shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
            --transition: all 0.3s ease;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            background-color: var(--bg-light);
            color: var(--text-primary);
            padding-top: 56px;
            padding-bottom: 70px;
        }
        
        /* 顶部导航 */
        .top-nav {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 56px;
            background-color: var(--bg-white);
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 16px;
            z-index: 1000;
            border-bottom: 1px solid var(--border-light);
        }
        
        .nav-title {
            font-size: 1.15rem;
            font-weight: 600;
            text-align: center;
            flex: 1;
        }
        
        .nav-btn {
            background: none;
            border: none;
            color: var(--text-secondary);
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: var(--transition);
        }
        
        .nav-btn:hover {
            background-color: var(--bg-light);
            color: var(--primary);
        }
        
        /* 筛选面板 */
        .filter-panel {
            background-color: var(--bg-white);
            padding: 12px 16px;
            border-bottom: 1px solid var(--border-light);
        }
        
        /* 高级搜索栏 */
        .advanced-search {
            margin-bottom: 16px;
        }
        
        .search-input-group {
            position: relative;
        }
        
        .search-input {
            width: 100%;
            padding: 10px 16px 10px 40px;
            border: 1px solid var(--border-light);
            border-radius: 20px;
            font-size: 0.9rem;
            background-color: var(--bg-light);
            transition: var(--transition);
        }
        
        .search-input:focus {
            outline: none;
            border-color: var(--primary-light);
            background-color: white;
            box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
        }
        
        .search-icon {
            position: absolute;
            left: 14px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-secondary);
        }
        
        /* 筛选条件区域 */
        .filters-container {
            margin-bottom: 16px;
        }
        
        .filter-section {
            margin-bottom: 14px;
        }
        
        .filter-label {
            font-size: 0.9rem;
            font-weight: 500;
            margin-bottom: 8px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .filter-expand-btn {
            color: var(--primary);
            background: none;
            border: none;
            font-size: 0.8rem;
            display: flex;
            align-items: center;
            gap: 4px;
        }
        
        /* 标签式筛选选项 */
        .filter-options {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 8px;
        }
        
        .filter-option {
            padding: 4px 12px;
            border-radius: 16px;
            font-size: 0.85rem;
            border: 1px solid var(--border-light);
            color: var(--text-secondary);
            background-color: var(--bg-light);
            cursor: pointer;
            transition: var(--transition);
        }
        
        .filter-option.active {
            background-color: var(--primary);
            color: white;
            border-color: var(--primary);
        }
        
        .filter-option:hover:not(.active) {
            border-color: var(--primary-light);
            color: var(--primary);
        }
        
        /* 滑块筛选 */
        .range-filter {
            padding: 8px 0;
        }
        
        .range-labels {
            display: flex;
            justify-content: space-between;
            font-size: 0.8rem;
            color: var(--text-secondary);
            margin-bottom: 6px;
        }
        
        .custom-range {
            width: 100%;
            height: 4px;
            background-color: var(--border-light);
            border-radius: 2px;
            appearance: none;
            outline: none;
        }
        
        .custom-range::-webkit-slider-thumb {
            appearance: none;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background-color: var(--primary);
            cursor: pointer;
        }
        
        /* 筛选按钮组 */
        .filter-actions {
            display: flex;
            gap: 10px;
            margin-top: 12px;
        }
        
        .reset-filters {
            flex: 1;
            padding: 8px;
            background-color: var(--bg-light);
            color: var(--text-secondary);
            border: 1px solid var(--border-light);
            border-radius: 8px;
            font-size: 0.9rem;
            transition: var(--transition);
        }
        
        .apply-filters {
            flex: 1;
            padding: 8px;
            background-color: var(--primary);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 0.9rem;
            transition: var(--transition);
        }
        
        .apply-filters:hover {
            background-color: var(--primary-dark);
        }
        
        .reset-filters:hover {
            background-color: #e5e7eb;
        }
        
        /* 活跃筛选标签 */
        .active-filters {
            padding: 8px 16px;
            background-color: var(--bg-white);
            border-bottom: 1px solid var(--border-light);
            display: flex;
            align-items: center;
            gap: 8px;
            overflow-x: auto;
            scrollbar-width: none;
        }
        
        .active-filters::-webkit-scrollbar {
            display: none;
        }
        
        .active-filter-tag {
            display: flex;
            align-items: center;
            gap: 6px;
            padding: 4px 10px;
            background-color: rgba(99, 102, 241, 0.1);
            color: var(--primary);
            border-radius: 16px;
            font-size: 0.8rem;
            white-space: nowrap;
        }
        
        .remove-filter {
            background: none;
            border: none;
            color: var(--primary);
            width: 16px;
            height: 16px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.7rem;
        }
        
        /* AI列表 */
        .ai-list {
            padding: 10px 16px;
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        
        .ai-item {
            background-color: var(--bg-white);
            border-radius: var(--radius);
            padding: 16px;
            box-shadow: var(--shadow);
            transition: var(--transition);
        }
        
        .ai-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }
        
        .ai-header {
            display: flex;
            align-items: center;
            margin-bottom: 12px;
        }
        
        .ai-avatar {
            width: 56px;
            height: 56px;
            border-radius: 12px;
            object-fit: cover;
            margin-right: 12px;
            border: 2px solid var(--primary-light);
        }
        
        .ai-info {
            flex: 1;
        }
        
        .ai-name {
            font-weight: 600;
            font-size: 1.05rem;
            margin-bottom: 2px;
            display: flex;
            align-items: center;
        }
        
        .ai-badge {
            font-size: 0.7rem;
            background-color: var(--primary-light);
            color: white;
            padding: 1px 6px;
            border-radius: 4px;
            margin-left: 6px;
        }
        
        .ai-meta {
            font-size: 0.8rem;
            color: var(--text-light);
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }
        
        .ai-description {
            font-size: 0.95rem;
            line-height: 1.6;
            margin-bottom: 12px;
            color: var(--text-primary);
        }
        
        /* 图片容器 */
        .images-container {
            margin-bottom: 12px;
            border-radius: 8px;
            overflow: hidden;
        }
        
        .single-image {
            width: 100%;
            border-radius: 8px;
            overflow: hidden;
        }
        
        .single-image img {
            width: 100%;
            aspect-ratio: 16/9;
            object-fit: cover;
        }
        
        .multiple-images {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 4px;
        }
        
        .image-item {
            aspect-ratio: 1;
            overflow: hidden;
        }
        
        .image-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        
        /* 特性标签 */
        .features-container {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 12px;
        }
        
        .feature-tag {
            padding: 3px 10px;
            background-color: var(--bg-light);
            border-radius: 12px;
            font-size: 0.8rem;
            color: var(--primary);
        }
        
        /* 操作栏 */
        .ai-actions {
            display: flex;
            justify-content: space-between;
            padding-top: 8px;
            border-top: 1px solid var(--border-light);
        }
        
        .action-btn {
            display: flex;
            align-items: center;
            gap: 6px;
            color: var(--text-secondary);
            font-size: 0.85rem;
            background: none;
            border: none;
            padding: 6px 0;
            transition: var(--transition);
        }
        
        .action-btn:hover {
            color: var(--primary);
        }
        
        .chat-btn {
            background-color: var(--primary);
            color: white;
            border: none;
            padding: 6px 16px;
            border-radius: 20px;
            font-size: 0.9rem;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: var(--transition);
        }
        
        .chat-btn:hover {
            background-color: var(--primary-dark);
        }
        
        /* 推荐指数 */
        .rating {
            display: flex;
            align-items: center;
            color: #f59e0b;
            font-size: 0.85rem;
        }
        
        .rating i {
            margin-right: 2px;
        }
        
        /* 底部导航 */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 65px;
            background-color: var(--bg-white);
            display: flex;
            justify-content: space-around;
            align-items: center;
            border-top: 1px solid var(--border-light);
            z-index: 1000;
        }
        
        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: var(--text-secondary);
            font-size: 0.7rem;
            text-decoration: none;
        }
        
        .nav-item i {
            font-size: 1.25rem;
            margin-bottom: 4px;
        }
        
        .nav-item.active {
            color: var(--primary);
        }
        
        /* 加载更多 */
        .load-more {
            margin: 16px 0;
            padding: 10px;
            text-align: center;
            color: var(--primary);
            font-size: 0.9rem;
            background-color: var(--bg-white);
            border-radius: var(--radius);
            border: 1px solid var(--border-light);
            transition: var(--transition);
        }
        
        /* 筛选结果计数 */
        .results-count {
            padding: 8px 16px;
            font-size: 0.85rem;
            color: var(--text-secondary);
            background-color: var(--bg-white);
            border-bottom: 1px solid var(--border-light);
        }
        
        /* 空状态 */
        .empty-state {
            padding: 40px 20px;
            text-align: center;
            color: var(--text-secondary);
        }
        
        .empty-state i {
            font-size: 3rem;
            margin-bottom: 16px;
            color: var(--border-light);
        }
    </style>
</head>
<body>
    <!-- 顶部导航 -->
    <div class="top-nav">
        <button class="nav-btn" id="backBtn">
            <i class="fas fa-arrow-left"></i>
        </button>
        <div class="nav-title">AI交友</div>
        <button class="nav-btn" id="sortBtn">
            <i class="fas fa-sort"></i>
        </button>
    </div>
    
    <!-- 筛选面板 -->
    <div class="filter-panel">
        <!-- 高级搜索栏 -->
        <div class="advanced-search">
            <div class="search-input-group">
                <i class="fas fa-search search-icon"></i>
                <input type="text" class="search-input" placeholder="搜索AI名称、特性或描述...">
            </div>
        </div>
        
        <!-- 筛选条件区域 -->
        <div class="filters-container">
            <!-- 类型筛选 -->
            <div class="filter-section">
                <div class="filter-label">
                    <span>AI类型</span>
                    <button class="filter-expand-btn" data-target="type-options">
                        <span>展开</span>
                        <i class="fas fa-chevron-down"></i>
                    </button>
                </div>
                <div class="filter-options" id="type-options">
                    <div class="filter-option">聊天陪伴</div>
                    <div class="filter-option">学习助手</div>
                    <div class="filter-option">创意设计</div>
                    <div class="filter-option">生活顾问</div>
                    <div class="filter-option">娱乐互动</div>
                    <div class="filter-option">职业指导</div>
                    <div class="filter-option">情感倾听</div>
                </div>
            </div>
            
            <!-- 功能特性筛选 -->
            <div class="filter-section">
                <div class="filter-label">
                    <span>功能特性</span>
                    <button class="filter-expand-btn" data-target="feature-options">
                        <span>展开</span>
                        <i class="fas fa-chevron-down"></i>
                    </button>
                </div>
                <div class="filter-options" id="feature-options">
                    <div class="filter-option">实时聊天</div>
                    <div class="filter-option">语音交互</div>
                    <div class="filter-option">内容生成</div>
                    <div class="filter-option">个性化推荐</div>
                    <div class="filter-option">多语言支持</div>
                    <div class="filter-option">24/7在线</div>
                </div>
            </div>
            
            <!-- 评分筛选 -->
            <div class="filter-section">
                <div class="filter-label">
                    <span>最低评分</span>
                    <button class="filter-expand-btn" data-target="rating-range">
                        <span>展开</span>
                        <i class="fas fa-chevron-down"></i>
                    </button>
                </div>
                <div class="range-filter" id="rating-range">
                    <div class="range-labels">
                        <span>3.0</span>
                        <span id="rating-value">4.0</span>
                        <span>5.0</span>
                    </div>
                    <input type="range" min="3" max="5" step="0.1" value="4" class="custom-range" id="rating-slider">
                </div>
            </div>
            
            <!-- 内容形式筛选 -->
            <div class="filter-section">
                <div class="filter-label">
                    <span>内容形式</span>
                    <button class="filter-expand-btn" data-target="content-options">
                        <span>展开</span>
                        <i class="fas fa-chevron-down"></i>
                    </button>
                </div>
                <div class="filter-options" id="content-options">
                    <div class="filter-option">纯文字</div>
                    <div class="filter-option">带图片</div>
                    <div class="filter-option">带视频</div>
                    <div class="filter-option">带语音</div>
                </div>
            </div>
            
            <!-- 活跃度筛选 -->
            <div class="filter-section">
                <div class="filter-label">
                    <span>活跃度</span>
                    <button class="filter-expand-btn" data-target="activity-options">
                        <span>展开</span>
                        <i class="fas fa-chevron-down"></i>
                    </button>
                </div>
                <div class="filter-options" id="activity-options">
                    <div class="filter-option">高活跃</div>
                    <div class="filter-option">中活跃</div>
                    <div class="filter-option">新上线</div>
                </div>
            </div>
        </div>
        
        <!-- 筛选按钮组 -->
        <div class="filter-actions">
            <button class="reset-filters" id="resetFilters">重置筛选</button>
            <button class="apply-filters" id="applyFilters">应用筛选</button>
        </div>
    </div>
    
    <!-- 活跃筛选标签 -->
    <div class="active-filters" id="activeFilters">
        <!-- 活跃筛选标签会动态添加到这里 -->
        <div class="active-filter-placeholder" style="color: var(--text-light); font-size: 0.85rem;">
            未选择筛选条件
        </div>
    </div>
    
    <!-- 筛选结果计数 -->
    <div class="results-count" id="resultsCount">
        找到 24 个符合条件的AI
    </div>
    
    <!-- AI列表 -->
    <div class="ai-list" id="aiList">
        <!-- AI项1 - 聊天类型 -->
        <div class="ai-item">
            <div class="ai-header">
                <img src="https://picsum.photos/id/1005/200/200" alt="AI头像" class="ai-avatar">
                <div class="ai-info">
                    <div class="ai-name">
                        心灵伴侣
                        <span class="ai-badge">情感</span>
                    </div>
                    <div class="ai-meta">
                        <span>聊天陪伴</span>
                        <span>·</span>
                        <div class="rating">
                            <i class="fas fa-star"></i>
                            <span>4.9</span>
                        </div>
                        <span>·</span>
                        <span>高活跃</span>
                    </div>
                </div>
            </div>
            
            <div class="ai-description">
                专注于情感陪伴的AI，擅长倾听和提供情感支持。无论你是想分享快乐，还是倾诉烦恼，我都会认真倾听并给予温暖回应。
            </div>
            
            <div class="features-container">
                <span class="feature-tag">实时聊天</span>
                <span class="feature-tag">情感支持</span>
                <span class="feature-tag">倾听者</span>
                <span class="feature-tag">24/7在线</span>
            </div>
            
            <div class="ai-actions">
                <button class="action-btn">
                    <i class="far fa-heart"></i>
                    <span>收藏</span>
                </button>
                <button class="action-btn">
                    <i class="far fa-comment"></i>
                    <span>1.2k 对话</span>
                </button>
                <button class="chat-btn">
                    <i class="fas fa-comments"></i>
                    <span>开始聊天</span>
                </button>
            </div>
        </div>
        
        <!-- AI项2 - 学习类型 -->
        <div class="ai-item">
            <div class="ai-header">
                <img src="https://picsum.photos/id/1027/200/200" alt="AI头像" class="ai-avatar">
                <div class="ai-info">
                    <div class="ai-name">
                        学习导师
                        <span class="ai-badge">教育</span>
                    </div>
                    <div class="ai-meta">
                        <span>学习助手</span>
                        <span>·</span>
                        <div class="rating">
                            <i class="fas fa-star"></i>
                            <span>4.6</span>
                        </div>
                        <span>·</span>
                        <span>中活跃</span>
                    </div>
                </div>
            </div>
            
            <div class="ai-description">
                专业AI学习导师，擅长各学科知识讲解和学习方法指导。可以帮助你理解难点知识，制定学习计划，提高学习效率。
            </div>
            
            <div class="images-container">
                <div class="single-image">
                    <img src="https://picsum.photos/id/20/800/450" alt="学习场景">
                </div>
            </div>
            
            <div class="features-container">
                <span class="feature-tag">内容生成</span>
                <span class="feature-tag">个性化推荐</span>
                <span class="feature-tag">多语言支持</span>
            </div>
            
            <div class="ai-actions">
                <button class="action-btn">
                    <i class="far fa-heart"></i>
                    <span>收藏</span>
                </button>
                <button class="action-btn">
                    <i class="far fa-comment"></i>
                    <span>8.2k 对话</span>
                </button>
                <button class="chat-btn">
                    <i class="fas fa-comments"></i>
                    <span>开始聊天</span>
                </button>
            </div>
        </div>
        
        <!-- 加载更多 -->
        <div class="load-more" id="loadMore">
            加载更多AI
        </div>
    </div>
    
    <!-- 底部导航 -->
    <div class="bottom-nav">
        <a href="#" class="nav-item">
            <i class="fas fa-home"></i>
            <span>首页</span>
        </a>
        <a href="#" class="nav-item active">
            <i class="fas fa-robot"></i>
            <span>AI交友</span>
        </a>
        <a href="#" class="nav-item">
            <i class="fas fa-comments"></i>
            <span>聊天</span>
        </a>
        <a href="#" class="nav-item">
            <i class="far fa-user"></i>
            <span>我的</span>
        </a>
    </div>
    
    <!-- Bootstrap JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        // 存储当前筛选条件
        const currentFilters = {
            type: [],
            feature: [],
            rating: 4.0,
            content: [],
            activity: []
        };
        
        // DOM元素
        const backBtn = document.getElementById("backBtn");
        const sortBtn = document.getElementById("sortBtn");
        const resetFiltersBtn = document.getElementById("resetFilters");
        const applyFiltersBtn = document.getElementById("applyFilters");
        const ratingSlider = document.getElementById("rating-slider");
        const ratingValue = document.getElementById("rating-value");
        const expandBtns = document.querySelectorAll(".filter-expand-btn");
        const filterOptions = document.querySelectorAll(".filter-option");
        const activeFiltersContainer = document.getElementById("activeFilters");
        const resultsCount = document.getElementById("resultsCount");
        const loadMoreBtn = document.getElementById("loadMore");
        const aiList = document.getElementById("aiList");
        const searchInput = document.querySelector(".search-input");
        
        // 初始化
        function init() {
            setupEventListeners();
        }
        
        // 设置事件监听
        function setupEventListeners() {
            // 返回按钮
            backBtn.addEventListener("click", () => {
                history.back();
            });
            
            // 排序按钮
            sortBtn.addEventListener("click", () => {
                showSortOptions();
            });
            
            // 筛选项展开/折叠
            expandBtns.forEach(btn => {
                btn.addEventListener("click", function() {
                    const targetId = this.getAttribute("data-target");
                    const targetElement = document.getElementById(targetId);
                    const icon = this.querySelector("i");
                    const text = this.querySelector("span");
                    
                    if (targetElement.style.display === "none") {
                        targetElement.style.display = "flex";
                        icon.classList.remove("fa-chevron-up");
                        icon.classList.add("fa-chevron-down");
                        text.textContent = "展开";
                    } else {
                        targetElement.style.display = "none";
                        icon.classList.remove("fa-chevron-down");
                        icon.classList.add("fa-chevron-up");
                        text.textContent = "收起";
                    }
                });
            });
            
            // 评分滑块
            ratingSlider.addEventListener("input", function() {
                const value = parseFloat(this.value).toFixed(1);
                ratingValue.textContent = value;
                currentFilters.rating = parseFloat(value);
            });
            
            // 筛选选项点击
            filterOptions.forEach(option => {
                option.addEventListener("click", function() {
                    // 获取选项所属类别
                    const optionParent = this.parentElement.id;
                    let category;
                    
                    switch(optionParent) {
                        case "type-options":
                            category = "type";
                            break;
                        case "feature-options":
                            category = "feature";
                            break;
                        case "content-options":
                            category = "content";
                            break;
                        case "activity-options":
                            category = "activity";
                            break;
                    }
                    
                    // 切换选中状态
                    this.classList.toggle("active");
                    
                    // 更新当前筛选条件
                    const optionText = this.textContent;
                    const index = currentFilters[category].indexOf(optionText);
                    
                    if (index === -1) {
                        currentFilters[category].push(optionText);
                    } else {
                        currentFilters[category].splice(index, 1);
                    }
                });
            });
            
            // 重置筛选
            resetFiltersBtn.addEventListener("click", resetFilters);
            
            // 应用筛选
            applyFiltersBtn.addEventListener("click", applyFilters);
            
            // 搜索功能
            searchInput.addEventListener("input", (e) => {
                const keyword = e.target.value.trim();
                // 延迟搜索，避免频繁触发
                clearTimeout(window.searchTimeout);
                window.searchTimeout = setTimeout(() => {
                    applyFilters(keyword);
                }, 500);
            });
            
            // 加载更多
            loadMoreBtn.addEventListener("click", loadMoreAIs);
        }
        
        // 重置筛选条件
        function resetFilters() {
            // 重置筛选数据
            Object.keys(currentFilters).forEach(key => {
                if (Array.isArray(currentFilters[key])) {
                    currentFilters[key] = [];
                } else {
                    currentFilters[key] = 4.0;
                }
            });
            
            // 重置UI
            filterOptions.forEach(option => {
                option.classList.remove("active");
            });
            
            ratingSlider.value = 4.0;
            ratingValue.textContent = "4.0";
            searchInput.value = "";
            
            // 清空活跃筛选标签
            updateActiveFilters();
            
            // 应用默认筛选
            applyFilters();
        }
        
        // 应用筛选条件
        function applyFilters(searchKeyword = "") {
            showLoading();
            
            // 模拟筛选延迟
            setTimeout(() => {
                // 构建筛选条件描述
                const filterDescription = [];
                
                if (searchKeyword) {
                    filterDescription.push(`搜索: ${searchKeyword}`);
                }
                
                Object.keys(currentFilters).forEach(key => {
                    if (Array.isArray(currentFilters[key]) && currentFilters[key].length > 0) {
                        filterDescription.push(`${getCategoryName(key)}: ${currentFilters[key].join(", ")}`);
                    } else if (!Array.isArray(currentFilters[key]) && currentFilters[key] !== 4.0) {
                        filterDescription.push(`最低评分: ${currentFilters[key]}`);
                    }
                });
                
                // 更新活跃筛选标签
                updateActiveFilters(filterDescription);
                
                // 模拟筛选结果计数
                const resultCount = Math.floor(Math.random() * 15) + 5; // 5-20之间的随机数
                resultsCount.textContent = `找到 ${resultCount} 个符合条件的AI`;
                
                hideLoading();
            }, 800);
        }
        
        // 更新活跃筛选标签
        function updateActiveFilters(filters = []) {
            // 清空容器
            activeFiltersContainer.innerHTML = "";
            
            if (filters.length === 0) {
                // 显示占位文本
                const placeholder = document.createElement("div");
                placeholder.className = "active-filter-placeholder";
                placeholder.style.color = "var(--text-light)";
                placeholder.style.fontSize = "0.85rem";
                placeholder.textContent = "未选择筛选条件";
                activeFiltersContainer.appendChild(placeholder);
            } else {
                // 添加筛选标签
                filters.forEach(filterText => {
                    const filterTag = document.createElement("div");
                    filterTag.className = "active-filter-tag";
                    
                    // 提取筛选类型和值
                    const [type, value] = filterText.split(": ");
                    
                    filterTag.innerHTML = `
                        <span>${value}</span>
                        <button class="remove-filter" data-type="${type}" data-value="${value}">
                            <i class="fas fa-times"></i>
                        </button>
                    `;
                    
                    activeFiltersContainer.appendChild(filterTag);
                    
                    // 为删除按钮添加事件
                    const removeBtn = filterTag.querySelector(".remove-filter");
                    removeBtn.addEventListener("click", function() {
                        const type = this.getAttribute("data-type");
                        const value = this.getAttribute("data-value");
                        
                        removeFilter(type, value);
                    });
                });
            }
        }
        
        // 移除单个筛选条件
        function removeFilter(type, value) {
            if (type === "搜索") {
                searchInput.value = "";
            } else if (type === "最低评分") {
                currentFilters.rating = 4.0;
                ratingSlider.value = 4.0;
                ratingValue.textContent = "4.0";
            } else {
                // 找到对应的分类
                let category;
                Object.keys(currentFilters).forEach(key => {
                    if (getCategoryName(key) === type) {
                        category = key;
                    }
                });
                
                // 从当前筛选条件中移除
                if (category && Array.isArray(currentFilters[category])) {
                    const values = value.split(", ");
                    values.forEach(v => {
                        const index = currentFilters[category].indexOf(v);
                        if (index !== -1) {
                            currentFilters[category].splice(index, 1);
                            
                            // 更新UI
                            filterOptions.forEach(option => {
                                if (option.textContent === v && 
                                    option.parentElement.id === `${category}-options`) {
                                    option.classList.remove("active");
                                }
                            });
                        }
                    });
                }
            }
            
            // 重新应用筛选
            applyFilters(searchInput.value.trim());
        }
        
        // 获取分类的显示名称
        function getCategoryName(key) {
            const names = {
                type: "AI类型",
                feature: "功能特性",
                content: "内容形式",
                activity: "活跃度",
                rating: "最低评分"
            };
            return names[key] || key;
        }
        
        // 显示排序选项
        function showSortOptions() {
            const sortOptions = [
                "推荐优先",
                "评分从高到低",
                "最新上线",
                "活跃度从高到低"
            ];
            
            // 创建排序选项弹窗
            const sortModal = document.createElement("div");
            sortModal.style.position = "fixed";
            sortModal.style.bottom = "65px";
            sortModal.style.left = "0";
            sortModal.style.right = "0";
            sortModal.style.backgroundColor = "white";
            sortModal.style.borderTopLeftRadius = "16px";
            sortModal.style.borderTopRightRadius = "16px";
            sortModal.style.boxShadow = "0 -2px 10px rgba(0,0,0,0.1)";
            sortModal.style.zIndex = "1001";
            sortModal.style.padding = "16px";
            
            // 添加标题
            const title = document.createElement("div");
            title.style.fontSize = "1rem";
            title.style.fontWeight = "600";
            title.style.marginBottom = "16px";
            title.textContent = "排序方式";
            sortModal.appendChild(title);
            
            // 添加选项列表
            sortOptions.forEach(option => {
                const optionEl = document.createElement("div");
                optionEl.style.padding = "12px 8px";
                optionEl.style.borderBottom = "1px solid var(--border-light)";
                optionEl.style.fontSize = "0.95rem";
                optionEl.textContent = option;
                optionEl.style.cursor = "pointer";
                
                // 点击事件
                optionEl.addEventListener("click", function() {
                    document.body.removeChild(sortModal);
                    document.body.removeChild(overlay);
                    showLoading();
                    
                    // 模拟排序延迟
                    setTimeout(() => {
                        hideLoading();
                    }, 600);
                });
                
                sortModal.appendChild(optionEl);
            });
            
            // 添加遮罩层
            const overlay = document.createElement("div");
            overlay.style.position = "fixed";
            overlay.style.top = "0";
            overlay.style.left = "0";
            overlay.style.right = "0";
            overlay.style.bottom = "0";
            overlay.style.backgroundColor = "rgba(0,0,0,0.5)";
            overlay.style.zIndex = "1000";
            
            overlay.addEventListener("click", function() {
                document.body.removeChild(sortModal);
                document.body.removeChild(overlay);
            });
            
            // 添加到页面
            document.body.appendChild(overlay);
            document.body.appendChild(sortModal);
        }
        
        // 加载更多AI
        function loadMoreAIs() {
            showLoading();
            
            // 模拟加载延迟
            setTimeout(() => {
                // 模拟新的AI数据
                const newAIs = [
                    {
                        id: 3,
                        name: "创意写手",
                        avatar: "https://picsum.photos/id/1062/200/200",
                        badge: "创作",
                        meta: "创意设计",
                        rating: 4.7,
                        activity: "中活跃",
                        description: "充满创意的AI写手，可以帮你构思故事、撰写文案、创作诗歌，让你的创作更加出色。",
                        images: [
                            "https://picsum.photos/id/24/300/300",
                            "https://picsum.photos/id/42/300/300"
                        ],
                        features: ["内容生成", "创意构思", "多语言支持"],
                        conversations: "6.9k"
                    },
                    {
                        id: 4,
                        name: "生活助手",
                        avatar: "https://picsum.photos/id/1074/200/200",
                        badge: "工具",
                        meta: "生活顾问",
                        rating: 4.5,
                        activity: "高活跃",
                        description: "全能生活助手，可以帮你管理日程、设置提醒、查询天气、推荐餐厅，让生活更便捷。",
                        images: [],
                        features: ["实时聊天", "个性化推荐", "24/7在线"],
                        conversations: "4.3k"
                    }
                ];
                
                // 添加到列表
                newAIs.forEach(ai => {
                    const aiElement = createAIElement(ai);
                    aiList.insertBefore(aiElement, loadMoreBtn);
                });
                
                hideLoading();
            }, 1000);
        }
        
        // 创建AI元素
        function createAIElement(ai) {
            const aiElement = document.createElement("div");
            aiElement.className = "ai-item";
            
            // 构建图片容器HTML
            let imagesHtml = "";
            if (ai.images && ai.images.length > 0) {
                imagesHtml = `<div class="images-container">
                    <div class="multiple-images">`;
                
                ai.images.forEach((img, index) => {
                    imagesHtml += `
                        <div class="image-item">
                            <img src="${img}" alt="AI相关图片 ${index + 1}">
                        </div>
                    `;
                });
                
                imagesHtml += `</div></div>`;
            }
            
            // 构建特性标签HTML
            let featuresHtml = "";
            if (ai.features && ai.features.length > 0) {
                featuresHtml = `<div class="features-container">`;
                ai.features.forEach(feature => {
                    featuresHtml += `<span class="feature-tag">${feature}</span>`;
                });
                featuresHtml += `</div>`;
            }
            
            // 组装HTML
            aiElement.innerHTML = `
                <div class="ai-header">
                    <img src="${ai.avatar}" alt="AI头像" class="ai-avatar">
                    <div class="ai-info">
                        <div class="ai-name">
                            ${ai.name}
                            <span class="ai-badge">${ai.badge}</span>
                        </div>
                        <div class="ai-meta">
                            <span>${ai.meta}</span>
                            <span>·</span>
                            <div class="rating">
                                <i class="fas fa-star"></i>
                                <span>${ai.rating}</span>
                            </div>
                            <span>·</span>
                            <span>${ai.activity}</span>
                        </div>
                    </div>
                </div>
                
                <div class="ai-description">
                    ${ai.description}
                </div>
                
                ${imagesHtml}
                
                ${featuresHtml}
                
                <div class="ai-actions">
                    <button class="action-btn">
                        <i class="far fa-heart"></i>
                        <span>收藏</span>
                    </button>
                    <button class="action-btn">
                        <i class="far fa-comment"></i>
                        <span>${ai.conversations} 对话</span>
                    </button>
                    <button class="chat-btn">
                        <i class="fas fa-comments"></i>
                        <span>开始聊天</span>
                    </button>
                </div>
            `;
            
            // 绑定事件
            const favoriteBtn = aiElement.querySelector(".action-btn:first-child");
            const chatBtn = aiElement.querySelector(".chat-btn");
            
            favoriteBtn.addEventListener("click", function() {
                const icon = this.querySelector("i");
                if (icon.classList.contains("far")) {
                    icon.classList.remove("far");
                    icon.classList.add("fas");
                    this.style.color = "#6366f1";
                } else {
                    icon.classList.remove("fas");
                    icon.classList.add("far");
                    this.style.color = "";
                }
            });
            
            chatBtn.addEventListener("click", function() {
                const aiName = aiElement.querySelector(".ai-name").textContent.trim().split(" ")[0];
                alert(`进入与 ${aiName} 的聊天界面`);
            });
            
            return aiElement;
        }
        
        // 显示加载状态
        function showLoading() {
            // 替换加载更多按钮为加载中状态
            if (loadMoreBtn) {
                loadMoreBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 加载中...';
                loadMoreBtn.style.pointerEvents = "none";
            }
        }
        
        // 隐藏加载状态
        function hideLoading() {
            // 恢复加载更多按钮
            if (loadMoreBtn) {
                loadMoreBtn.innerHTML = "加载更多AI";
                loadMoreBtn.style.pointerEvents = "auto";
            }
        }
        
        // 初始化页面
        document.addEventListener("DOMContentLoaded", init);
    </script>
</body>
</html>
